/**
 * 餐桌管理
 */
var dinnerTable = {

    errorCB : function(tx, error) {
        alert("Error processing SQL: " + err.code);
    },

    show : function(transition) {
        var db = app.getDB();
        db.transaction(function(tx) {
            tx.executeSql('select * from dinner_table order by sort', [], function(tx, results) {
                var len = results.rows.length;
                var template = $.createTemplateURL('templates/dinner_table.html');
                var data = [];
                for (var i = 0; i < len; i++) {
                    data.push(results.rows.item(i));
                }
                var html = template.get(data);
                app.loadHTML(html, {
                    transition : transition
                })

            }, errorCB);

        }, errorCB);
    },
    showAdd : function() {
        app.loadPage('templates/dinner_table_add.html', {
            transition : 'pop-in'
        });
        this.initEvent();
    },
    showEdit : function(data) {
        app.loadPage('templates/dinner_table_add.html', {
            transition : 'pop-in'
        });
        this.initEvent();
    },
    update :function(){
    	var db = app.getDB();
		db.transaction(function(tx) {
			tx.executeSql('update dinner_table set name =? , sort = ? where id = ?', [name, sort, id],
			function(tx, results) {
				
			}, errorCB);

		}, errorCB);
    },
    add:function(){
    	var db = app.getDB();
    	var me=this;
		db.transaction(function(tx) {
			tx.executeSql('insert into dinner_table (name,sort) VALUES(?,?)', [name, sort], function(tx, results) {
				me.show('slide-right');
			}, errorCB);

		}, errorCB);
    },
   
    initEvent:function(){
        $("#dinner_table_save_btn").on("click",function(){
        	
        	alert("test");
            
        });
    }

};